<template>
	<view class="app_Cont">
		<scroll-view class="showCont" scroll-y="true" @scrolltolower="scrolltolower" lower-threshold="10" v-if="showCont">
			<view class="formCont">
				<view class="formHead">
					<view class="formHeadName">我的账单</view>
					<view class="formHeadCount">合计消费（{{Math.abs(totalMoney)}}元）</view>
				</view>
				<view :class="index==0?'noTop recordItem':'recordItem'" :key="index" v-for="(item,index) in listArr">
					<view class="itemLeft">
						<view class="orderNum">{{item.user_bill_number}}</view>
						<view class="orderTime">{{item.create_time}}</view>
					</view>
					<view :class="item.lx==1?'orderPrice redText':'orderPrice'">
						<text v-if="item.lx==2">+</text>
						{{item.user_bill_money}}元
						<text v-if="item.lx==2">(已退款)</text>
					</view>
				</view>
				<noData v-if="listArr.length==0&&!isChange"></noData>
				<loadMore v-if="!isChange&&last_page==page"></loadMore>
			</view>
		</scroll-view>
		<load v-if="!showCont||isChange"></load>
	</view>
</template>

<script>
	import api from '@/http/api.js'
	import load from '@/components/load.vue'
	import noData from '@/components/noData.vue'
	import loadMore from '@/components/loadMore.vue'
	export default {
		components:{noData,load,loadMore},
		data() {
			return {
				showCont:false,
				isChange:false,
				totalMoney:'0.00',
				listArr:[],
				page:1,
				per_page:10,
				last_page:0,
			};
		},
		methods:{
			scrolltolower(){
				if(this.page<this.last_page){
					this.page++
					this.isChange = true
					this.getData()
				}
			},
			getData(){
				let data = {
					pay_status:this.navId,
					page:this.page,
					per_page:this.per_page,
				}
				api.getRequst(data,'/api/My/userBill').then((res)=>{
					if(res.code==1){
						let arr = res.data.data
						for(let item of arr){
							this.listArr.push(item)
						}
						this.last_page = res.data.last_page
					}
					this.showCont = true
					this.isChange = false
				})
			},
			getTotal(){
				let data = {}
				api.getRequst(data,'/api/My/getPayMoney').then((res)=>{
					if(res.code==1){
						this.totalMoney = res.data
					}
				})
			}
		},
		async onLoad() {
			await this.getData()
			this.getTotal()
		}
	}
</script>

<style lang="scss">
.showCont{
	padding: 30rpx 4%;
	height: 100vh;
	overflow-y: auto;
	box-sizing: border-box;
	.formCont{
		background-color: #fff;
		border-radius: 30rpx;
		padding: 30rpx 30rpx 50rpx;
		width: 100%;
		box-sizing: border-box;
		.formHead{
			display: flex;
			align-items: center;
			justify-content: space-between;
			.formHeadName{
				font-size: 32rpx;
				font-weight: bold;
			}
		}
		.recordItem{
			display: flex;
			justify-content: space-between;
			padding: 30rpx 0;
			align-items: center;
			box-sizing: border-box;
			border-top: 1px dashed #ddd;
			.itemLeft{
				flex: 1;
				width: 100rpx;
				.orderNum{
					font-weight: bold;
				}
				.orderTime{
					color: #999;
					font-size: 24rpx;
					margin-top: 10rpx;
				}
			}
			.orderPrice{
				color: #3f55cc;	
			}
			.redText{
				color: #ff5757;
			}
		}
		.noTop{
			border-top: none;
		}
	}
	.endTip{
		color: #999;
		text-align: center;
		margin-top: 30rpx;
	}
}
</style>
